package com.example.mq.rabbitmq.service;

import com.example.mq.rabbitmq.cansts.DirectExchangeEnum;
import com.example.mq.rabbitmq.cansts.DirectQueueEnum;
import com.example.mq.rabbitmq.config.RabbitMQTopicConfig;
import com.example.mq.rabbitmq.po.Message;
import com.example.mq.rabbitmq.po.TestMessage;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.UUID;

/**
 * @author xyh
 * @description
 * @date 2021/3/31 15:40
 */
@Service
public class MQService implements IService{

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Override
    public void sendMsg(String message,String key) {

        TestMessage testMessage = new TestMessage();
        testMessage.setContent(message);

        Message<TestMessage> msg = new Message<>();
        msg.setId(UUID.randomUUID().toString());
        msg.setTimeStamp(new Date().getTime());
        msg.setData(testMessage);
        rabbitTemplate.convertAndSend(RabbitMQTopicConfig.topicExchange, key,msg);

    }
}
